package com.kitty.game.friend.model;

import org.nutz.dao.entity.annotation.ColDefine;
import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Comment;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
//后加
import com.kitty.game.friend.model.Friend;
import com.kitty.game.friend.model.FriendGroup;
import com.kitty.game.friend.model.FriendRefuse;

public class FriendBox {

    private ArrayList<Friend> friends = new ArrayList<>();

    @Comment("拒绝陌生人消息等级")
    private short strangerLevel = 70;
    @Comment("拒绝陌生人添加等级")
    private short refuseLevel = 70;
    private String autoReplyMsg;

    @Column
    @Comment("好友分组")
    @ColDefine(width = 2048)
    private List<FriendGroup> friendGroup;

    /**
     * 验证请求
     */
    private Map<Long, Long> verifyMap;
    /**
     * 拒绝列表
     */
    private Map<Long, FriendRefuse> refuseMap;
    /**
     * 连续私聊数量(有回复时清空)
     */
    private Map<Long, Short> chatCountMap;

    public ArrayList<Friend> getFriends() {
        return friends;
    }

    public void setFriends(ArrayList<Friend> friends) {
        this.friends = friends;
    }

    public short getStrangerLevel() {
        return strangerLevel;
    }

    public void setStrangerLevel(short strangerLevel) {
        this.strangerLevel = strangerLevel;
    }

    public short getRefuseLevel() {
        return refuseLevel;
    }

    public void setRefuseLevel(short refuseLevel) {
        this.refuseLevel = refuseLevel;
    }

    /**
     * 根据GID返回好友对象
     */
    public Friend getFriendByGid(String gid) {
        for (Friend friend : getFriends()) {
            if (friend.getGid().equals(gid)) {
                return friend;
            }
        }
        return null;
    }

    /**
     * 根据好友角色名返回好友对象
     */
    public Friend getFriendByName(String Name) {
        for (Friend friend : getFriends()) {
            if (friend.getFriendName().equals(Name)) {
                return friend;
            }
        }
        return null;
    }

    /**
     * 删除好友
     */
    public void removeFriend(Friend remove) {
        for (Friend friend : this.friends) {
            if (friend.getGid().equals(remove.getGid())) {
                this.getFriends().remove(remove);
                break;
            }
        }
    }

    /**
     * 获得uid对应的私聊数量
     */
    public short getChatCount(long uid) {
        if (chatCountMap != null) {
            return chatCountMap.getOrDefault(uid, (short)0);
        }
        return 0;
    }

    /**
     * 增加uid对应的私聊数量
     */
    public void addChatCount(long uid) {
        if (chatCountMap == null) {
            chatCountMap = new ConcurrentHashMap<>();
        }
        short count = (short) (chatCountMap.getOrDefault(uid, (short)0) + 1);
        chatCountMap.put(uid, count);
    }

    /**
     * 清除uid对应的私聊数量
     */
    public void removeChatCount(long uid) {
        if (chatCountMap != null) {
            chatCountMap.remove(uid);
        }
    }

    public List<FriendGroup> getFriendGroup() {
        return friendGroup;
    }

    public void setFriendGroup(List<FriendGroup> friendGroup) {
        this.friendGroup = friendGroup;
    }

    public Map<Long, Long> getVerifyMap() {
        return verifyMap;
    }

    public void setVerifyMap(Map<Long, Long> verifyMap) {
        this.verifyMap = verifyMap;
    }

    public Map<Long, FriendRefuse> getRefuseMap() {
        return refuseMap;
    }

    public void setRefuseMap(Map<Long, FriendRefuse> refuseMap) {
        this.refuseMap = refuseMap;
    }

    public Map<Long, Short> getChatCountMap() {
        return chatCountMap;
    }

    public void setChatCountMap(Map<Long, Short> chatCountMap) {
        this.chatCountMap = chatCountMap;
    }

    public String getAutoReplyMsg() {
        return autoReplyMsg;
    }

    public void setAutoReplyMsg(String autoReplyMsg) {
        this.autoReplyMsg = autoReplyMsg;
    }
}
